//package com.eastfair.messagecenter.rocket;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.eastfair.auth.entity.UserAccount;
//import com.eastfair.cache.repository.CachePlusOps;
//import com.eastfair.core.base.R;
//import com.eastfair.core.context.ContextUtil;
//import com.eastfair.core.point.BusinBasePoint;
//import com.eastfair.messagecenter.ContentModel;
//import com.eastfair.messagecenter.domain.TaskInfo;
//import com.eastfair.messagecenter.enumeration.BusinessCode;
//import com.eastfair.messagecenter.enumeration.ChannelType;
//import com.eastfair.messagecenter.model.EmailContentModel;
//import com.eastfair.messagecenter.model.InnerContentModel;
//import com.eastfair.messagecenter.model.SmsContentModel;
//import com.eastfair.messagecenter.pipeline.ProcessContext;
//import com.eastfair.messagecenter.pipeline.ProcessController;
//import com.eastfair.messagecenter.pipeline.SendTaskModel;
//import com.eastfair.messagecenter.point.ReadySendPoint;
//import com.eastfair.messagecenter.point.SendPoint;
//import com.eastfair.messagecenter.service.ConsumeService;
//import com.eastfair.mq.model.MySimpleMessage;
//import com.eastfair.mq.service.AbstractPointService;
//import com.eastfair.mq.service.BusinessPointService;
//import com.eastfair.point.PointKeyDefinition;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.BeanUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.util.ArrayList;
//import java.util.List;
//
//
///**
// * <p>
// * 单业务处理事件
// * </p>
// *
// * @author ligang
// * @date 2021-08-10
// */
//@Slf4j
//@Service
//public class BusinessPointServiceImpl extends AbstractPointService implements BusinessPointService {
//    @Autowired
//    private CachePlusOps cachePlusOps;
//
//    @Autowired
//    private ProcessController processController;
//
//    @Autowired
//    ConsumeService consumeService;
//
//    @Override
//    public void executeBusin(MySimpleMessage mySimpleMessage) {
//        log.info("BusinessPointServiceImpl is execute message is " + JSONObject.toJSONString(mySimpleMessage));
//        BusinBasePoint businBasePoint = JSONObject.parseObject(JSONObject.toJSONString(mySimpleMessage.getPayload()), BusinBasePoint.class);
//        JSONObject jsonObject = (JSONObject) businBasePoint.getPointObj();
//        String businPointName = jsonObject.getString("pointName");
//
//        Long projectId = ContextUtil.getProjectId();
//
//        Long subSystemId = ContextUtil.getSubSystemId();
//
//
//        if (businPointName.equals(PointKeyDefinition.MESSAGE_READY_SEND_POINT)) {
//            //预发送
//            ReadySendPoint readySendPoint = assmbleReadySendPoint(businBasePoint.getPointObj().toString());
//            //封装任务model
//            SendTaskModel sendTaskModel = SendTaskModel.builder()
//                    .readySendPoint(readySendPoint)
//                    .build();
//            //责任链model
//            ProcessContext context = ProcessContext.builder()
//                    .code(BusinessCode.COMMON_SEND)
//                    .processModel(sendTaskModel)
//                    .needBreak(false)
//                    .response(R.success()).build();
//            //启动责任链
//            ProcessContext process = processController.process(context);
//
//        } else if (businPointName.equals(PointKeyDefinition.MESSAGE_SEND_POINT)) {
//            //真实发送
//            SendPoint sendPoint = assmbleSendPoint(businBasePoint.getPointObj().toString());
//            consumeService.consumeSend(sendPoint.getTaskInfoLists());
//        }
//    }
//
//    public SendPoint assmbleSendPoint(String pointObjStr) {
//        SendPoint sendPoint = JSON.parseObject(pointObjStr, SendPoint.class);
//        //发送
//        List<TaskInfo> taskInfoLists = new ArrayList<>();
//        JSONObject jsonObject = JSONObject.parseObject(pointObjStr);
//        JSONArray jsonArray = jsonObject.getJSONArray("taskInfoLists");
//        for (int i = 0; i < jsonArray.size(); i++) {
//            TaskInfo taskInfo =jsonArray.getObject(i,TaskInfo.class);
//            JSONObject contentModelObject =  jsonArray.getJSONObject(i).getJSONObject("contentModel");
//            String contentModelType = contentModelObject.getString("contentModelType");
//            if (ChannelType.INNER_IM.getCodeEn().equals(contentModelType)) {
//                InnerContentModel innerContentModel = JSONObject.parseObject(contentModelObject.toJSONString(), InnerContentModel.class);
//                taskInfo.setContentModel(innerContentModel);
//            } else if (ChannelType.SMS.getCodeEn().equals(contentModelType)) {
//                SmsContentModel smsContentModel = JSONObject.parseObject(contentModelObject.toJSONString(), SmsContentModel.class);
//                taskInfo.setContentModel(smsContentModel);
//            } else if (ChannelType.EMAIL.getCodeEn().equals(contentModelType)) {
//                EmailContentModel emailContentModel = JSONObject.parseObject(contentModelObject.toJSONString(), EmailContentModel.class);
//                taskInfo.setContentModel(emailContentModel);
//            }
//            taskInfoLists.add(taskInfo);
//        }
//        sendPoint.setTaskInfoLists(taskInfoLists);
//        return sendPoint;
//    }
//
//
//
//    public ReadySendPoint assmbleReadySendPoint(String pointObjStr) {
//        ReadySendPoint readySendPoint = JSON.parseObject(pointObjStr, ReadySendPoint.class);
//        //预发送
//        List<ContentModel> contentModelList = new ArrayList<>();
//        JSONObject jsonObject = JSONObject.parseObject(pointObjStr);
//        JSONArray jsonArray = jsonObject.getJSONArray("contentModelList");
//        for (int i = 0; i < jsonArray.size(); i++) {
//            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
//            String contentModelType = jsonObject1.getString("contentModelType");
//            if (ChannelType.INNER_IM.getCodeEn().equals(contentModelType)) {
//                InnerContentModel innerContentModel = JSONObject.parseObject(jsonObject1.toJSONString(), InnerContentModel.class);
//                contentModelList.add(innerContentModel);
//            } else if (ChannelType.SMS.getCodeEn().equals(contentModelType)) {
//                SmsContentModel smsContentModel = JSONObject.parseObject(jsonObject1.toJSONString(), SmsContentModel.class);
//                contentModelList.add(smsContentModel);
//            } else if (ChannelType.EMAIL.getCodeEn().equals(contentModelType)) {
//                EmailContentModel emailContentModel = JSONObject.parseObject(jsonObject1.toJSONString(), EmailContentModel.class);
//                contentModelList.add(emailContentModel);
//            }
//        }
//        readySendPoint.setContentModelList(contentModelList);
//        return readySendPoint;
//    }
//
//}
